package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.model.SmsHomeNewProduct;
import com.jie.langlangmall.service.SmsHomeNewProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/25
 * @Email 3217998214@qq.com
 * @Description 新品推荐管理
 */
@RestController
@Tag(name = "SmsHomeNewProductController", description = "首页新品管理")
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    private SmsHomeNewProductService homeNewProductService;

    @Operation(summary = "添加首页新品")
    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody List<SmsHomeNewProduct> homeNewProductList) {
        homeNewProductService.create(homeNewProductList);
        return CommonResult.success();
    }

    @Operation(summary = "修改新品排序")
    @PostMapping("/update/sort/{id}")
    public CommonResult<?> updateSort(@PathVariable Long id, Integer sort) {
        homeNewProductService.updateSort(id, sort);
        return CommonResult.success();
    }

    @Operation(summary = "批量删除新品")
    @PostMapping("/delete")
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        homeNewProductService.delete(ids);
        return CommonResult.success();
    }

    @Operation(summary = "批量修改新品推荐状态")
    @PostMapping("/update/recommendStatus")
    public CommonResult<?> updateRecommendStatus(@RequestParam("ids") List<Long> ids,
                                                 @RequestParam("recommendStatus") Integer recommendStatus) {
        homeNewProductService.updateRecommendStatus(ids, recommendStatus);
        return CommonResult.success();
    }

    @Operation(summary = "分页查询首页新品")
    @GetMapping("/list")
    public CommonResult<CommonPage<SmsHomeNewProduct>> list(@RequestParam(value = "productName", required = false) String productName,
                                                            @RequestParam(value = "recommendStatus", required = false) Integer recommendStatus,
                                                            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<SmsHomeNewProduct> homeNewProductList = homeNewProductService.list(productName, recommendStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(homeNewProductList));
    }

    // TODO: 删除商品的时候，注意冗余表
}
